import java.util.Arrays;
//消失的数字
public class Solution1 {
        public static int missingNumber(int[] nums) {
            Arrays.sort(nums);
            for(int i = 0; i < nums.length-1; i++) {
                if (nums[i + 1] - nums[i] != 1) {
                    return (nums[i + 1] + nums[i]) / 2;
                }
            }
            if(nums[0] != 0){
                return 0;
            }else return nums[nums.length-1] + 1;
        }
        public static int missingNumber2(int[] nums) {
            int ret = 0;
            for (int i = 0; i < nums.length; i++) {
                ret ^= nums[i];
                ret ^= i;
            }
            return ret ^= (nums.length);
        }
        public static void main(String[] args) {
            int[] nums = {0,1,3};
            int ret = missingNumber(nums);
            System.out.println(ret);
            int ret2 = missingNumber2(nums);
            System.out.println(ret2);
        }
}
